/**
 * @file PrivateData.hpp
 *
 *  @date 2009-06-01
 *  @author hauleth
 */

#ifndef PRIVATEDATA_HPP_
#define PRIVATEDATA_HPP_

#include <Bust/Threads/Thread.hpp>

#include <pthread.h>

namespace bust {

class ThreadPrivateData {
		friend class Thread;
		friend class ThreadPrivateActions;
	private:
		ThreadPrivateData() {
		}

		virtual ~ThreadPrivateData() {
		}

		volatile bool isRunning;
		volatile bool isCanceled;
		volatile bool idSet;
		pthread_t tid;
		volatile int uniqueId;
		static int nextId;
		static pthread_key_t s_tls_key;
};

struct ThreadCleanupStruct {
		Thread *thread;
		volatile bool *runflag;
};

class MutexPrivateData {
	private:
		MutexPrivateData() {};
		virtual ~MutexPrivateData() {
		}
		pthread_mutex_t mutex;
		friend class Mutex;
		friend class Condition;
};

class ConditionPrivateData {
    friend class Condition;
private:
    ConditionPrivateData() {};
    virtual ~ConditionPrivateData() {};
    pthread_cond_t condition;
};

class BarrierPrivateData {
    friend class Barrier;
private:
    BarrierPrivateData() {};
    virtual ~BarrierPrivateData() {};
    pthread_cond_t     cond;            // cv for waiters at barrier
    pthread_mutex_t    lock;            // mutex for waiters at barrier
    volatile int       maxcnt;          // number of threads to wait for
    volatile int       cnt;             // number of waiting threads
    volatile int       phase;           // flag to seperate two barriers
};

}

#endif /* PRIVATEDATA_HPP_ */
